package com.qianyu.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qianyu.project.core.context.user.FlowUserManager;
import com.qianyu.project.entity.SystemAuthority;
import com.qianyu.project.mapper.SystemAuthorityMapper;
import com.qianyu.project.service.ISystemAuthorityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;

import java.util.List;

/**
 * @author gs
 * @date create in 2020/12/24 8:22
 */
@Service
@Transactional(rollbackFor = Exception.class)
@Validated
public class SystemAuthorityServiceImpl implements ISystemAuthorityService {

    @Autowired
    private SystemAuthorityMapper systemAuthorityMapper;
    @Autowired
    private FlowUserManager flowUserManager;

    @Override
    public SystemAuthority getByAuthorityName(String authorityName) {
        return systemAuthorityMapper.selectOne(
                new QueryWrapper<SystemAuthority>()
                .like("authority_name", authorityName)
        );
    }

    @Override
    public List<SystemAuthority> listAndFlow() {
        return systemAuthorityMapper.listAndFlow();
    }

    @Override
    public List<SystemAuthority> getUpdateauthority(Integer moduleid) {
        return systemAuthorityMapper.getUpdateauthority(moduleid);
    }

    @Override
    public List<SystemAuthority> getByRole(String role) {
        return systemAuthorityMapper.selectByRole(role);
    }

    @Override
    public List<SystemAuthority> getRootList() {
        return systemAuthorityMapper.selectRootByRole(flowUserManager.getFlowUser().getUserRoles());
    }
}
